<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.List" %>
<%@page import="wo.bsys.dto.DictionaryDto" %>
<%@page import="com.qfedu.sem.dto.ProjectDto" %>
<%@page import="com.qfedu.sem.dto.BugVersionDto" %>
<%
	List<DictionaryDto> levels = (List<DictionaryDto>)request.getAttribute ("levels");
	List<DictionaryDto> rates = (List<DictionaryDto>)request.getAttribute ("rates");
	List<ProjectDto> projects = (List<ProjectDto>)request.getAttribute ("projects");
	List<BugVersionDto> versions = (List<BugVersionDto>)request.getAttribute ("versions");
%>
<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">提交故障</div>
				<div class="panel-body">
					<form role="form" id="semBugCreateForm" class="form-horizontal"
						action="${pageContext.request.contextPath}/sem/bug/create"
						method="post" enctype="multipart/form-data">
						<div class="form-group">
							<label class="col-sm-2 control-label">ID</label>
							<div class="col-sm-10">
								<input class="form-control" placeholder="请输入ID" name="id">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">标题</label>
							<div class="col-sm-10">
								<input class="form-control" placeholder="请输入标题"
									name="title">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">项目</label>
							<div class="input-group">
								<input type="hidden" name="projectId">
	                            <input type="text" class="form-control" name="projectName" readonly>
	                            <span class="input-group-btn woSingleSelect" wo:url="sem/project/selector">
	                                <button class="btn btn-default" type="button"><i class="fa fa-search"></i>
	                                </button>
	                            </span>
                            </div>
                        </div>
                        <div class="form-group">
							<label class="col-sm-2 control-label">版本</label>
							<div class="input-group">
								<input type="hidden" name="versionId">
	                            <input type="text" class="form-control" name="versionNo" readonly>
	                            <span class="input-group-btn woSingleSelect" wo:url="sem/bugVersion/selector">
	                                <button class="btn btn-default" type="button"><i class="fa fa-search"></i>
	                                </button>
	                            </span>
                            </div>
                        </div>
						<div class="form-group">
							<label class="col-sm-2 control-label">描述</label>
							<div class="col-sm-10">
								<input class="form-control" placeholder="请输入描述"
									name="description">
							</div>
						</div>
						<div class="form-group">
                            <label class="col-sm-2 control-label">故障级别</label>
                            <div class="col-sm-10">
	                            <select class="form-control" name="level">
	                            <% for (int i = 0; i < levels.size(); i ++) {
	                            	DictionaryDto dic = levels.get(i);
								%>
	                                <option value="<%=dic.getVal()%>" <%=(i==0)?"selected='selected'":""%>><%=dic.getName()%></option>
	                            <% } %>
	                            </select>
                            </div>
                        </div>
						<div class="form-group">
                            <label class="col-sm-2 control-label">故障频度</label>
                            <div class="col-sm-10">
	                            <select class="form-control" name="rate">
	                            <% for (int i = 0; i < rates.size(); i ++) {
	                            	DictionaryDto dic = rates.get(i);
								%>
	                                <option value="<%=dic.getVal()%>" <%=(i==0)?"selected='selected'":""%>><%=dic.getName()%></option>
	                            <% } %>
	                            </select>
	                         </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">截图</label>
                            <input type="file" name="imageFile">
                        </div>
                        <div class="form-group">
							<label class="col-sm-2 control-label">修复人</label>
							<div class="input-group">
								<input type="hidden" name="fixerId">
								<input type="text" class="form-control" name="fixerName" readonly>
								<span class="input-group-btn woSingleSelect" wo:url="department/staff/selector">
									<button class="btn btn-default" type="button">
										<i class="fa fa-search"></i>
									</button>
								</span>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">测试人</label>
							<div class="input-group">
								<input type="hidden" name="testerId"> <input type="text"
									class="form-control" name="testerName" readonly> <span
									class="input-group-btn woSingleSelect"
									wo:url="department/staff/selector">
									<button class="btn btn-default" type="button">
										<i class="fa fa-search"></i>
									</button>
								</span>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-2"></div>
							<div class="col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>
								<button type="reset" class="btn btn-default">重置</button>
								<button type="button" class="btn btn-warning"
									onclick="location.href='${pageContext.request.contextPath}/'">返回</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<!-- /.panel-body -->
	</div>
	<script type="text/javascript">
	$(document).ready(function () {
    	// 设置各字段的验证规则
    	var fields = {
    		fixerName : {
    			validators : {
    				notEmpty : {
    					message : '请选择修复人！'
    				}
    			}
    		},
    		testerName : {
    			validators : {
    				notEmpty : {
    					message : '请选择测试人！'
    				}
    			}
    		}
    	};
  		// 将验证规则应用到表单的字段中
		$('#semBugCreateForm').bootstrapValidator({
			// 设置不同字段的验证规则和错误信息
            // fields: fields,			
            // 默认错误消息
			message: '输入值不合法',
			// 设置验证成功或者失败的图标
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            }
        });
  		
		// 关联对象选择器按钮点击事件
	    $('#semBugCreateForm .input-group-btn').click (function () {
	    	// 1.创建模态框
	    	// 创建层semBugDialog，如果之前该层存在，就删除
			$('#semBugDialog').remove();
        	$('body').append ('<div class="modal fade" id="semBugDialog" tabindex="-1" role="dialog" aria-labelledby="semBugSelectorModalLabel"></div>');
        	// 2.设置模态框内容加载的参数
        	var nameField = $(this).prev().attr ('name');
			var idField = $(this).prev().prev().attr ('name');
        	var loadOpts = {
           		formId : 'semBugCreateForm',
           		idField : idField,
           		nameField : nameField,
           		singleSelect : $(this).hasClass('woSingleSelect')
           	};
        	if (idField == 'versionId') {// 是否点击的版本选择按钮
        		loadOpts.params = $('#semBugCreateForm input[name=projectId]').val();
        	}
        	if (idField == 'projectId') {// 是否点击项目选择按钮
        		loadOpts.callback = "selectSemBugProject";
        	}
        	// 3.加载模态框的内容，并显示
        	$('#semBugDialog').load ('${pageContext.request.contextPath}/' + $(this).attr('wo:url'), 
        		loadOpts, function () {
        		$('#semBugDialog').modal ('show');
        	});
		});
		
		window.selectSemBugProject = function () {
			$('#semBugCreateForm input[name=versionId]').val('');
			$('#semBugCreateForm input[name=versionNo]').val('');
		}
    });	
	</script>
</div>